<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <div id="main"></div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  data() {
    return {
      reports: {}
    }
  },

  created() {
    this.getReports()
  },
  mounted() {
    this.initCharts()
  },

  methods: {
    async getReports() {
      const res = await this.$axios.get('reports/type/1')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)

      // x轴贴边
      res.data.xAxis[0].boundaryGap = false
      res.data.tooltip = {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          label: {
            backgroundColor: '#6a7985'
          }
        }
      }
      this.reports = res.data
    },
    async initCharts() {
      await this.getReports()
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById('main'))
      // 绘制图表
      myChart.setOption(this.reports)
    }
  }
}
</script>

<style scoped lang='less'>
#main {
  margin-top: 20px;
  height: 500px;
}
</style>
